# Utility class to read the data and parse them into a feature vector
# list.
class DataReader():
  # Read the feature vectors.
  def __init__(self, filename):
    self.feature_vectors = []
    self.num_features = 0

    in_file = open(filename)
    for line in in_file:
      line = line.strip()
      parts = line.split(' ')
      num_parts = len(parts)

      # Set the number of feature vectors
      if self.num_features == 0:
        self.num_features = num_parts - 1

      # All feature vectors must be of the same size
      if self.num_features != num_parts - 1:
        continue

      self.feature_vectors.append((parts[:num_parts - 1], parts[num_parts - 1]))
    in_file.close()

  # Returns the number of feature vectors
  def get_num_features(self):
    return self.num_features

  # Returns the parsed feature vectors
  def get_feature_vectors(self):
    return self.feature_vectors

  # Returns the number of feature vectors
  def get_num_feature_vectors(self):
    return len(self.feature_vectors)

  # Returns the feature vector at index idx
  def get_feature_vector(self, idx):
    return self.feature_vectors[idx]
